

public class Market {
    String name;
    String site;
    int count = 0;
    MarketUser []user = new MarketUser[100];

    public boolean xinyonhu(String card, String username, String telephone, int grade){

        if(count>=user.length){
            System.out.println("用户达到上限");
            return false;
        }

        for (int i = 0; i < count; i++) {
            if (user[i].card.equals(card)) {
                System.out.println("会员号重复");
                return false;
            }
        }

        user[count]=new MarketUser();
        user[count].card=card;
        user[count].username=username;
        user[count].telephone=telephone;
        user[count].grade=grade;
        count++;
        return true;
    }
    public boolean jiafen(String card, int num){

        for (int i = 0; i < count; i++) {
            if (user[i].card.equals(card)) {
                user[i].grade = user[i].grade + num;
                return true;
            }
        }
        System.out.println("帐号不存在");
        return false;
    }
    public String duihuan(String card, int num){
        for(int i=0;i<count;i++){
            if(user[i].card.equals(card)) {
                if(user[i].grade<num)
                    return null;
                user[i].grade = user[i].grade - num;
                return "兑换成功";
            }
        }
        return null;
    }
    public void xinxi(){
        for(int i=0;i<count;i++){
            System.out.println(user[i].card+"  "+user[i].username+"  "+user[i].telephone+"  "+user[i].grade);
        }
    }

}
